package com.example.mobile2021606140lhq0508homework;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class SupplierActivity extends AppCompatActivity {

    private TextView tvSupplierTitle;
    private RadioGroup radBtnSupplierName;
    private RadioButton radBtnSupplier1;
    private RadioButton radBtnSupplier2;
    private RadioButton radBtnSupplier3;
    private RadioButton radBtnSupplier4;
    private RadioButton radBtnSupplier5;
    private RadioButton radBtnSupplier6;
    private RadioButton radBtnSupplier7;
    private RadioButton radBtnSupplier8;
    private RadioButton radBtnSupplier9;
    private RadioButton radBtnSupplier10;
    private RadioButton radBtnSupplier11;
    private Button btnSUpplierbmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supplier);
        initView();

        btnSUpplierbmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int radBtnId=radBtnSupplierName.getCheckedRadioButtonId();
                if (radBtnId!=-1){
                    RadioButton radBtn=findViewById(radBtnId);
                    Intent intent=new Intent();
                    intent.putExtra("supplier",radBtn.getText().toString());
                    setResult(RESULT_OK,intent);
                    finish();

                }else {
                    new AlertDialog.Builder(SupplierActivity.this).setMessage("请选择原材料")
                            .setPositiveButton("确定",null).create().show();


                }

            }
        });

    }

    private void initView() {
        tvSupplierTitle = findViewById(R.id.tvSupplierTitle);
        radBtnSupplierName = findViewById(R.id.radBtnSupplierName);
        radBtnSupplier1 = findViewById(R.id.radBtnSupplier1);
        radBtnSupplier2 = findViewById(R.id.radBtnSupplier2);
        radBtnSupplier3 = findViewById(R.id.radBtnSupplier3);
        radBtnSupplier4 = findViewById(R.id.radBtnSupplier4);
        radBtnSupplier5 = findViewById(R.id.radBtnSupplier5);
        radBtnSupplier6 = findViewById(R.id.radBtnSupplier6);
        radBtnSupplier7 = findViewById(R.id.radBtnSupplier7);
        radBtnSupplier8 = findViewById(R.id.radBtnSupplier8);
        radBtnSupplier9 = findViewById(R.id.radBtnSupplier9);
        radBtnSupplier10 = findViewById(R.id.radBtnSupplier10);
        radBtnSupplier11 = findViewById(R.id.radBtnSupplier11);
        btnSUpplierbmit = findViewById(R.id.btnSUpplierbmit);
    }
}